﻿@section header {
    <script type="text/javascript">
        /**
        * chw 2011.4.7
        * panel: 主面板
        */
        Ext.onReady(function () {
            var panel = Ext.create('Ext.panel.Panel', {
                region: 'center',
                layout: 'fit',
                defaults: {
                    flex: 1 //子元素平均分配宽度
                },
                split: true,
                autoScroll: true,
                bodyPadding: 6,
                border: 0,
                padding: 0,
                margin: 0,
                tbar: [
                          { xtype: 'label', text: '权限管理 -> 分级权限', cls: 'formNav' },
                          { xtype: 'tbfill' },
                          { xtype: 'button', iconCls: 'helpIcon', tooltip: '帮助', tooltipType: 'title', handle: function (source, e) { alert('帮助!') } }
                          ]/*,
                bbar: [
                          { xtype: 'button', text: 'Button 1', handler: function (source, e) { openWindow(); } }
                        ],
                html: ''*/
            });
            new Ext.container.Viewport({
                layout: 'fit',
                border: 0,
                padding: 0,
                items: [
                panel
                ]
            });

            Ext.regModel('user', {
                //            fields: ['ID','privilegeName', 'resourceCode', 'privilegeCode']
                fields: [
            { name: 'ID', type: 'int' },
            { name: 'userCode', type: 'string' },
            { name: 'userName', type: 'string' },
            { name: 'privilegeCode', type: 'string' },
            { name: 'privilegeName', type: 'string' },
            { name: 'path', type: 'string' }
            ]
            });

            var roleGrid = new Ext.grid.GridPanel({
                title: '用户列表',
                store: new Ext.data.ArrayStore({
                    model: 'user',
                    sorters: ['ID'],
                    data: [
                    ['1', 'admin', '超级管理员', 'abc', '公文处理','角色A,角色B',],
                    ['2', 'lilin', '李林', 'abc', '系统管理', '角色A,角色B', ],
                    ['3', 'lxf', 'lxf', 'abc', '设计科', '角色A,角色B', ],
                    ['4', 'lxx', 'lxx', 'abc', '办公室', '角色A,角色B', ],
                    ['5', 'wh', 'wh', 'abc', '设计科','角色A,角色B', ],
                    ['6', 'zm', 'zm', 'abc', '设计科', '角色A,角色B', ],
                    ['7', 'wzheng', 'wzheng', 'abc', '设计科', '角色A,角色B', ],
                    ['8', 'xq', 'xq', 'abc', '设计科','角色A,角色B', ],
                    ['9', 'ljm', 'ljm', 'abc', '设计科', '角色A,角色B', ],
                    ['10', 'df', 'df', 'abc', '设计科', '角色A,角色B', ]
                ]
                }),
                //margin: 6,
                autoScroll: true,
                border: 0,
                padding: 0,
                bodyPadding: 0,
                stripeRows: true,
                plugins: [new Ext.grid.CellEditing({ clicksToEdit: 2 })],
                selModel: { selType: 'cellmodel' },
                tbar: [
                          { xtype: 'label', iconCls: 'iconNew', text: '用户名称: ', style: { margin: "0 4"} },
                          { xtype: 'textfield', iconCls: 'iconEdit', text: '', tooltip: '用户', tooltipType: 'title', handler: function (source, e) { Ext.getCmp('grid001').view.refresh(); } },
                          { xtype: 'button', iconCls: 'iconEdit', text: '', tooltip: '查询', tooltipType: 'title', handler: function (source, e) { Ext.getCmp('grid001').view.refresh(); } },
                          { xtype: 'tbseparator' },
                                                    { xtype: 'label', iconCls: 'iconNew', text: '权限名称: ', style: { margin: "0 4"} },
                          { xtype: 'textfield', iconCls: 'iconEdit', text: '', tooltip: '权限', tooltipType: 'title', handler: function (source, e) { Ext.getCmp('grid001').view.refresh(); } },
                          { xtype: 'button', iconCls: 'iconEdit', text: '', tooltip: '查询', tooltipType: 'title', handler: function (source, e) { Ext.getCmp('grid001').view.refresh(); } },
                          { xtype: 'tbfill' },
                          { xtype: 'button', iconCls: 'iconRefresh', text: '', tooltip: '刷新', tooltipType: 'title', handler: function (source, e) { alert('刷新!') } }
                        ],
                frame: true,
                columns: [
                new Ext.grid.RowNumberer(),
                {
                    text: 'ID',
                    dataIndex: 'ID',
                    width: 100,
                    hidden: true
                }, {
                    text: '用户编码',
                    dataIndex: 'userCode',
                    width: 100,
                    field: { allowBlank: false }
                }, {
                    text: '用户名称',
                    dataIndex: 'userName',
                    width: 160,
                    field: { allowBlank: false },
                    renderer: function (v) { return '<a href="#">' + v + '</a>'; }
                }, {
                    text: '权限编码',
                    dataIndex: 'privilegeCode',
                    width: 100,
                    field: { allowBlank: false }
                }, {
                    text: '权限名称',
                    dataIndex: 'privilegeName',
                    width: 100,
                    field: { allowBlank: false }
                }, {
                    text: '角色途径',
                    dataIndex: 'path',
                    flex:1,
                    field: { allowBlank: false }
                }],
                viewConfig: {
                    listeners: {
                        //                    itemdblclick: function (view, record, el, index, e) { /*alert(record.get("ID"))*/winMR.show(this) },
                        itemclick: function (view, record, el, index, e) {
                            //debugger;
                            //uGrid.setTitle(record.data.Name + ' - 分级管理用户');
                            //privilegeGrid.setTitle(record.data.Name + ' - 分级管理权限');
                            //debugger;
                            //roleGrid.store.getAt(0).set('privilegeName', 'ddddddddddddd');
                            //debugger;
                            //roleGrid.store.getAt(0).dirty = true;
                            //roleGrid.getView().refreshNode(0);
                            roleGrid.getView().refresh();
                            //                        debugger;
                            //                        roleGrid.store.load();
                        }
                    }
                }
            }); // grid


            panel.add(roleGrid);

        });                               // Ext.onReady

            
    </script>
}
